import Vue from 'vue'
import Router from 'vue-router'
import Home from '@/views/Home.vue'
import router from '@/router/index'

console.log(router)

Vue.use(Router)


const imports = (path, folder = '/home') => {
  if (path.indexOf('.vue') == -1) path += '/index.vue'
  return () => import('@/views' + folder + path)
}

export default new Router({
  mode: 'history',
  base: process.env.BASE_URL,
  routes: [
    {
      path: '/',
      component    : Home,
      children: [
        ...router.map(route => {
          return {
            path: route.path,
            name: route.name,
            component: imports(route.file),
            meta: {
              crumb: route.crumb
            }
          }
        })
      ]
    },
    {
      path: '/about',
      name: 'about',
      component: () => import(/* webpackChunkName: "about" */ './views/About.vue')
    },
  ]
})
